package com.google.android.exoplayer2.extractor.ts;

import android.util.SparseArray;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.extractor.ts.TsPayloadReader.b;
import com.google.android.exoplayer2.extractor.ts.TsPayloadReader.d;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import o.afx;
import o.afy;
import o.afz;
import o.aga;
import o.agd;
import o.age;
import o.agf;
import o.agg;
import o.agi;
import o.agj;
import o.agk;
import o.ago;
import o.agt;
import o.agu;
import o.agy;
import o.ajr;
import o.anc;

public final class DefaultTsPayloadReaderFactory implements d {
    private final List<Format> ˊ;
    private final int ॱ;

    public DefaultTsPayloadReaderFactory() {
        this(0);
    }

    public DefaultTsPayloadReaderFactory(int i) {
        this(i, Collections.singletonList(Format.ˊ(null, "application/cea-608", 0, null)));
    }

    public DefaultTsPayloadReaderFactory(int i, List<Format> list) {
        this.ॱ = i;
        this.ˊ = list;
    }

    public SparseArray<TsPayloadReader> ॱ() {
        return new SparseArray();
    }

    public TsPayloadReader ˎ(int i, b bVar) {
        switch (i) {
            case 2:
                return new agj(new agd(ˏ(bVar)));
            case 3:
            case 4:
                return new agj(new agi(bVar.ˊ));
            case 15:
                if (ˎ(2)) {
                    return null;
                }
                return new agj(new afy(false, bVar.ˊ));
            case 17:
                if (ˎ(2)) {
                    return null;
                }
                return new agj(new agk(bVar.ˊ));
            case 21:
                return new agj(new agf());
            case 27:
                if (ˎ(4)) {
                    return null;
                }
                return new agj(new age(ॱ(bVar), ˎ(1), ˎ(8)));
            case 36:
                return new agj(new agg(ॱ(bVar)));
            case 89:
                return new agj(new afz(bVar.ˎ));
            case 129:
            case 135:
                return new agj(new aga(bVar.ˊ));
            case 130:
                if (ˎ(64)) {
                    return null;
                }
                break;
            case 134:
                if (ˎ(16)) {
                    return null;
                }
                return new ago(new agu());
            case 138:
                break;
            default:
                return null;
        }
        return new agj(new afx(bVar.ˊ));
    }

    private agt ॱ(b bVar) {
        return new agt(ˋ(bVar));
    }

    private agy ˏ(b bVar) {
        return new agy(ˋ(bVar));
    }

    private List<Format> ˋ(b bVar) {
        if (ˎ(32)) {
            return this.ˊ;
        }
        anc o_anc = new anc(bVar.ˏ);
        List<Format> list = this.ˊ;
        while (o_anc.ˊ() > 0) {
            int ˋ = o_anc.ˋ() + o_anc.ʽ();
            if (o_anc.ʽ() == 134) {
                List<Format> arrayList = new ArrayList();
                int ʽ = o_anc.ʽ() & 31;
                for (int i = 0; i < ʽ; i++) {
                    String str;
                    int i2;
                    String ˊ = o_anc.ˊ(3);
                    int ʽ2 = o_anc.ʽ();
                    Object obj = (ʽ2 & DnsConfig.MAX_CACHE_ENTRIES) != 0 ? 1 : null;
                    if (obj != null) {
                        str = "application/cea-708";
                        i2 = ʽ2 & 63;
                    } else {
                        str = "application/cea-608";
                        i2 = 1;
                    }
                    byte ʽ3 = (byte) o_anc.ʽ();
                    o_anc.ˎ(1);
                    List list2 = null;
                    if (obj != null) {
                        list2 = ajr.ˎ((ʽ3 & 64) != 0);
                    }
                    arrayList.add(Format.ˏ(null, str, null, -1, 0, ˊ, i2, null, Long.MAX_VALUE, list2));
                }
                list = arrayList;
            }
            o_anc.ˋ(ˋ);
        }
        return list;
    }

    private boolean ˎ(int i) {
        return (this.ॱ & i) != 0;
    }
}
